package com.siyuanren.gcocp.service.impl;

import com.siyuanren.gcocp.consts.GcocpConsts;
import com.siyuanren.gcocp.dto.ContentDTO;
import com.siyuanren.gcocp.entity.WxUserFavorite;
import com.siyuanren.gcocp.entity.WxUserFavoriteExample;
import com.siyuanren.gcocp.mapper.MyWxContentMapper;
import com.siyuanren.gcocp.mapper.base.WxUserFavoriteMapper;
import com.siyuanren.gcocp.service.ContentService;
import com.siyuanren.gcocp.vo.QueryChildContentVO;
import com.siyuanren.gcocp.vo.QueryContentVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.service.impl
 * Date         2018/4/18
 * Time         14:27
 * Description
 */
@Slf4j
@Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    MyWxContentMapper mapper;
    @Autowired
    WxUserFavoriteMapper userFavoriteMapper;

    @Override
    public List<ContentDTO> getContentList(QueryContentVO queryContentVO) throws Exception {
        List<ContentDTO> contentList = mapper.getContentList(queryContentVO);
        for (ContentDTO contentDTO : contentList) {
            // 是否收藏
            WxUserFavoriteExample example = new WxUserFavoriteExample();
            example.or().andUserIdEqualTo(queryContentVO.getUserId())
                    .andContentIdEqualTo(contentDTO.getId())
                    .andAvailableEqualTo(true);
            List<WxUserFavorite> wxUserFavorites = userFavoriteMapper.selectByExample(example);
            if (!wxUserFavorites.isEmpty()) {
                contentDTO.setFavId(wxUserFavorites.get(0).getId());
            }
        }
        return contentList;
    }

    @Override
    public List<ContentDTO> getChildContentList(QueryChildContentVO queryChildContentVO) throws Exception {
        List<ContentDTO> childContentList = mapper.getChildContentList(queryChildContentVO);
        return childContentList;
    }

}
